package com.pzr.soccer.model;

import lombok.Data;

import java.io.Serializable;

/**
 * 公共的返回值对象
 *
 * @param <T>
 */
@Data
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 成功
     */
    public static final int SUCCESS = 2000;

    /**
     * 失败
     */
    public static final int FAIL = 5000;

    private int code;

    private String msg;

    private T data;

    private RT tag;

    public static <T> R<T> ok() {
        return restResult(null, SUCCESS, "none",null);
    }

    public static <T> R<T> ok(T data) {
        return restResult(data, SUCCESS, null,null);
    }
    
    public static <T> R<T> ok(String msg) {
        return restResult(null, SUCCESS, msg,null);
    }

    public static <T> R<T> ok(T data, String msg, RT tag) {
        return restResult(data, SUCCESS, msg,tag);
    }

    public static <T> R<T> ok(T data, RT tag) {
        return restResult(data, SUCCESS, null,tag);
    }

    public static <T> R<T> ok(String msg, RT tag) {
        return restResult(null, SUCCESS, msg,tag);
    }

    public static <T> R<T> ok(T data,String msg){
        return  restResult(data,SUCCESS,msg,null);
    }
    public static <T> R<T> fail() {
        return restResult(null, FAIL, null,null);
    }


    public static <T> R<T> fail(T data) {
        return restResult(data, FAIL, null,null);
    }

    public static <T> R<T> fail(String msg) {
        return restResult(null, FAIL, msg,null);
    }
    
    public static <T> R<T> fail(T data, String msg, RT tag) {
        return restResult(data, FAIL, msg,tag);
    }

    public static <T> R<T> fail(int code, RT tag) {
        return restResult(null, code, null, tag);
    }
    public static <T> R<T> fail(String msg, RT tag) {
        return restResult(null, FAIL, msg, tag);
    }

    private static <T> R<T> restResult(T data, int code, String msg, RT tag) {
        R<T> apiResult = new R<>();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        apiResult.setTag(tag);
        return apiResult;
    }


}
